package com.wyh.controller;


import com.wyh.common.annotation.Log;
import com.wyh.common.annotation.RateLimiter;
import com.wyh.common.enums.BusinessType;
import com.wyh.common.response.PageInfo;
import com.wyh.common.result.R;
import com.wyh.common.util.ExcelUtils;
import com.wyh.entity.MsgMessage;
import com.wyh.request.MsgMessageRequest;
import com.wyh.service.IMsgMessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

/**
 * 【请填写功能名称】控制层
 *
 * @author WangYuHang
 * @date 2024-03-08
 */
@Slf4j
@AllArgsConstructor
@RestController
@Api(value = "【请填写功能名称】接口管理",tags = "【请填写功能名称】接口管理")
@RequestMapping("/admin/msgMessage" )
public class MsgMessageController {

    private final IMsgMessageService iMsgMessageService;




    /**
     * 好友发送消息
     */
    @ApiOperation(value = "好友发送消息")
    @PostMapping("/sendMessage")
    public R<PageInfo<MsgMessage>> sendMessage(@RequestBody MsgMessageRequest msgMessageRequest) {
        return R.success(iMsgMessageService.pageList(msgMessageRequest));
    }

    /**
     * 历史聊天记录
     */
    @ApiOperation(value = "分页查询【请填写功能名称】列表")
    @PostMapping("/pageList")
    public R<PageInfo<MsgMessage>> pageList(@RequestBody MsgMessageRequest msgMessageRequest) {
        return R.success(iMsgMessageService.pageList(msgMessageRequest));
    }

    /**
     * 撤回消息
     */
    @ApiOperation(value = "获取【请填写功能名称】详细信息")
    @GetMapping(value = "/query/{id}")
    public R<MsgMessage> detail(@PathVariable("id") Integer id) {
        return R.success(iMsgMessageService.getById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @Log(title = "新增【请填写功能名称】", businessType = BusinessType.INSERT)
    @RateLimiter
    @ApiOperation(value = "新增【请填写功能名称】")
    @PostMapping("/add")
    public R<Void> add(@RequestBody MsgMessageRequest msgMessageRequest) {
        iMsgMessageService.add(msgMessageRequest);
        return R.success();
    }

    /**
     * 修改【请填写功能名称】
     */
    @Log(title = "修改【请填写功能名称】", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "修改【请填写功能名称】")
    @PostMapping("/update")
    public R<Void> edit(@RequestBody MsgMessageRequest msgMessageRequest) {
        iMsgMessageService.update(msgMessageRequest);
        return R.success();
    }

    /**
     * 删除【请填写功能名称】
     */
    @Log(title = "删除【请填写功能名称】", businessType = BusinessType.DELETE)
    @ApiOperation(value = "删除【请填写功能名称】")
    @PostMapping("/delete/{ids}")
    public R<Void> remove(@PathVariable Integer[] ids) {
        iMsgMessageService.deleteBatch(Arrays.asList(ids));
        return R.success();
    }

    /**
    * 导出【请填写功能名称】
    *
    * @param response response
    * @throws IOException IOException
    */
    @PostMapping(value = "/export")
    public void exportExcel(HttpServletResponse response,@RequestBody MsgMessageRequest msgMessageRequest) throws IOException {
        List<MsgMessage> list = iMsgMessageService.list(msgMessageRequest);
        ExcelUtils.exportExcel(list, MsgMessage.class, "【请填写功能名称】信息", response);
    }
}
